package org.usmile.algorithms.huawei.acm;

import java.util.*;

// https://fcqian.blog.csdn.net/article/details/128380468
public class _整理扑克牌 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Integer[] cards = Arrays.stream(sc.nextLine().split(" ")).map(Integer::parseInt).toArray(Integer[]::new);
        Map<Integer, Integer> cardCount = new HashMap<>();
        for (int card : cards) {
            cardCount.put(card, cardCount.getOrDefault(card, 0) + 1);
        }

        LinkedList<int[]> booms = new LinkedList<>();
        LinkedList<Integer> three = new LinkedList<>();
        LinkedList<Integer> two = new LinkedList<>();
        LinkedList<Integer> one = new LinkedList<>();
        for (Map.Entry<Integer, Integer> entry : cardCount.entrySet()) {
            int card = entry.getKey();
            int count = entry.getValue();
            if (count >= 4) {
                booms.add(new int[]{card, count});
            } else if (count == 3) {
                three.add(card);
            } else if (count == 2) {
                two.add(card);
            } else {
                one.add(card);
            }
        }

        booms.sort(Comparator.comparingInt(o -> o[0] * o[1]));
        three.sort((o1, o2) -> o2 - o1);
        two.sort((o1, o2) -> o2 - o1);
        LinkedList<int[]> threeTwo = new LinkedList<>();
        while (three.size() > 0) {
            if (three.size() >= 2) {
                if (two.size() > 0) {
                    Integer first = three.removeFirst();
                    Integer threeMerge = three.get(0);
                    Integer twoMerge = two.get(0);
                    if (threeMerge > twoMerge) {
                        threeTwo.add(new int[]{first, threeMerge});
                        three.removeFirst();
                        one.add(threeMerge);
                    } else {
                        threeTwo.add(new int[]{first, twoMerge});
                        two.removeFirst();
                    }
                } else {
                    Integer first = three.removeFirst();
                    Integer threeMerge = three.removeFirst();
                    threeTwo.add(new int[]{first, threeMerge});
                }
            } else if (two.size() >= 1) {
                Integer first = three.removeFirst();
                Integer twoMerge = two.removeFirst();
                threeTwo.add(new int[]{first, twoMerge});
            } else {
                break;
            }
        }

        one.sort((o1, o2) -> o2 - o1);

        StringJoiner sj = new StringJoiner(" ");
        for (int[] boom : booms) {
            for (int i = 0; i < boom[1]; i++) {
                sj.add(boom[1] + "");
            }
        }
        for (int[] tt : threeTwo) {
            sj.add(tt[0] + "").add(tt[0] + "").add(tt[0] + "");
            sj.add(tt[1] + "").add(tt[1] + "");
        }
        for (int t : three) {
            sj.add(t + "").add(t + "").add(t + "");
        }
        for (int t : two) {
            sj.add(t + "").add(t + "");
        }
        for (int t : one) {
            sj.add(t + "");
        }

        System.out.println(sj.toString());
    }
}
